jQuery.fn.center = function(d) {
    var a = this;
    if (!d) {
        a.css("margin-top", $(window).height() / 2 - this.height() / 2);
        a.css("margin-left", $(window).width() / 2 - this.width() / 2);
        $(window).resize(function() {
            a.center(!d)
        })
    } else {
        var c = $(window).height() / 2 - this.height() / 2;
        var b = $(window).width() / 2 - this.width() / 2;
        c = (c < 0) ? 0: c;
        b = (b < 0) ? 0: b;
        a.stop();
        a.animate({
            marginTop: c,
            marginLeft: b
        },
        150, "linear")
    }
};